package com.blindBox.front.handler.loginHandler.loginHandlerImpl;

import com.blindBox.front.commonResult.MsgBackToFront;
import com.blindBox.front.dao_pojo.User;
import com.blindBox.front.handler.loginHandler.AbstractLoginHandler;
import com.blindBox.front.handler.verify.Verify;
import com.blindBox.front.handler.verify.loginVerifyImpl.UserLoginByTokenVerify;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;


@Component("loginByTokenHandler")
public class LoginByTokenHandler implements AbstractLoginHandler
{
    @Resource(name="uTokenVerify")
    private Verify userLoginByTokenVerify;
    private volatile User user;
    private volatile MsgBackToFront msgBackToFront=new MsgBackToFront(null,MsgBackToFront.EXCEPTION_ERROR);
    //解析出token的值，然后转换为user对象
    public synchronized LoginByTokenHandler parseTokenToUser(String token)
    {
        UserLoginByTokenVerify userLoginByTokenVerify = (UserLoginByTokenVerify) this.userLoginByTokenVerify;
        this.msgBackToFront=userLoginByTokenVerify.verify(token);
        return this;
    }
    //检验token的合法性
    public synchronized MsgBackToFront verifyToken(String token)
    {
        return  (MsgBackToFront)userLoginByTokenVerify.verify(token);
    }
    @Override
    public synchronized MsgBackToFront login()
    {
       return this.msgBackToFront;
    }
}
